home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9269 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: uwm.edu!daffy!uwvax!flisakow
  2. From: flisakow@.cs.wisc.edu (Shaun Flisakowski)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tradition or what?
  5. Date: 9 Mar 1996 00:53:17 GMT
  6. Organization: U of Wisconsin CS Dept
  7. Message-ID: <4hqkpt$lk7@spool.cs.wisc.edu>
  8. References: <4g0elg$mdr@redstone.interpath.net> <4hpd8a$d70@alterdial.UU.NET> <1996Mar8.153250.115645@kuhub.cc.ukans.edu> <4hqhge$2gu@solutions.solon.com>
  9. NNTP-Posting-Host: trigger.cs.wisc.edu
  10.  
  11. In article <4hqhge$2gu@solutions.solon.com>,
  12. Peter Seebach <seebs@solutions.solon.com> wrote:
  13. >In article <1996Mar8.153250.115645@kuhub.cc.ukans.edu>,
  14. > <anh@kuhub.cc.ukans.edu> wrote:
  15. >>Well, I found one good use of magic numbers such as when one needs a 
  16. >>localized temporary buffer of data.
  17. >
  18. >>int func()
  19. >>{
  20. >>    FILE *fp;
  21. >>    char buf[15+1];
  22. >
  23. >>    ...
  24. >
  25. >>    fgets(buf,15,fp);
  26. >>}
  27. >
  28. >>Well, if I know the data is always going to be less than 15 or whatever, 
  29. >>there is really no need to use a #define here.
  30. >
  31. >Anyway, I'd rather see a 15 in both places, and over that, I'd prefer to
  32. >see a #define or enum used.  If you know the data is always going to be
  33. [snip]
  34.  
  35.     I agree, for small little things like this, I sympathize with
  36.     the original author though, and drop in the define in-line,
  37.     undefining it at the end of that function:
  38.  
  39. int func()
  40. {
  41.  
  42.     FILE *fp;
  43. #define BUFF_SZE    15
  44.     char buf[BUFF_SZE];
  45.  
  46.     ...
  47.  
  48.     fgets(buf,BUFF_SZE,fp);
  49.  
  50.     ...
  51.  
  52. #undef  BUFF_SZE
  53.  
  54.  
  55. -- 
  56.     Shaun        flisakow@cs.wisc.edu
  57.  
  58.    "In your heart you know its flat."
  59.                            -Flat Earth Society
  60.